<template>
  <div class="admin-container">
    <!-- <div class="container-1200"> -->
      <div class="title mg-B20">项目活动表</div>
      
      <el-form
        :model="projectActivityForm"
        :rules="projectActivityRules"
        ref="projectActivityForm"
        label-width="100px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="projectActivityForm.projectName"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="活动名称" prop="activityName">
              <el-input v-model="projectActivityForm.activityName"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="级别" prop="jb">
              <el-select
                v-model="projectActivityForm.jb"
                placeholder="请选择企业等级注册类型"
              >
                <el-option
                  v-for="item in jbDict"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="活动主题" prop="activityTitle">
              <el-input v-model="projectActivityForm.activityTitle"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="举办单位" prop="company">
              <el-input v-model="projectActivityForm.company"> </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="活动时间" prop="activityDate">
              <el-date-picker
                v-model="projectActivityForm.activityDate"
                type="date"
                placeholder="请选择活动时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="活动地点" prop="address">
              <el-input v-model="projectActivityForm.address"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="相关资料（横幅、台上、台下）" prop="meta">
              <single-upload
                listType="picture-card"
                v-model="projectActivityForm.meta"
              ></single-upload>
            </el-form-item>
          </el-col>
        </el-row>
        
      </el-form>
    <!-- </div> -->
  </div>
</template>

<script>
import SingleUpload from "@/components/Upload/singleUpload";
import { find as companyFind } from "@/api/company";
import { list as dictList } from "@/api/dict";
import utils from "@/utils/utils.js";
import { validPhone, validPositiveIntAndZero } from "@/utils/validate.js";
import { find as projectFind } from "@/api/project";
import { update as projectActivityUpdate, find as projectActivityFind } from "@/api/projectActivity";

export default {
  components: { SingleUpload },
  name: "project",
  data() {
    const validateCapital = (rule, value, callback) => {
      if (utils.isNull(value)) {
        callback();
      } else if (!validPositiveIntAndZero(value)) {
        callback(new Error("必须为大于等于0的数值"));
      } else {
        callback();
      }
    };

    return {
      projectActivityForm: {
        projectId: "", //所属项目',
        projectName: "", //项目名称',
        jb: "", //级别(国际/国/省/市)',
        activityName: "", //活动名称',
        activityTitle: "", //活动主题',
        activityDate: "", //活动时间',
        address: "", //活动地点',
        company: "", //举办单位',
        meta: "", //相关资料（横幅、台上、台下）[{name:,url:}]',
        companyId: "", //
      },
      projectActivityRules: {
        projectName: [
          { required: true, message: "请输入项目名称", trigger: "blur" },
        ],
        jb: [
          { required: true, message: "请选择级别", trigger: "blur" },
        ],
        activityName: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
        ],
        activityDate: [
          { required: true, message: "请选择活动时间", trigger: "blur" },
        ],
      },

      projectId: "",
      projectInfo: {},
      companyId: "",
      companyInfo: {},

      jbDict: [],
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
    utils.getDictList("jb", (res) => {
      this.jbDict = res.data;
    });
    if (this.$route.query) {
      this.projectActivityForm.companyId = this.companyId =
        this.$route.query.companyId;
      this.projectActivityForm.projectId = this.projectId =
        this.$route.query.projectId;
        this.projectActivityId  =
        this.$route.query.projectActivityId;
        this.projectFind(this.projectId)
      this.projectActivityFind(this.projectActivityId);
    }
  },

  mounted() {},

  destroyed() {},

  methods: {
    //获取月报信息
    projectActivityFind(id) {
      projectActivityFind(id).then((res) => {
        console.log("获取月报信息--", res);
        if (res.type == "success") {
          this.projectActivityForm = res.data.projectActivity;
          this.projectActivityForm.createDate = utils.dateFormatter(this.projectActivityForm.createDate)
        }
      });
    },

    //获取公司信息
    companyFind(id) {
      companyFind(id).then((res) => {
        console.log("获取公司信息res--", res);
        if (res.type == "success") {
          this.companyInfo = res.data.company;
        }
      });
    },

    //获取项目信息
    projectFind(id) {
      let _this = this
      projectFind(id).then((res) => {
        console.log("获取项目信息--", res);
        if (res.type == "success") {
          _this.projectInfo = res.data.project;
          _this.projectActivityForm.projectName = res.data.project.projectName;
        }
      });
    },

    //表单提交事件
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          projectActivityUpdate(this.projectActivityForm)
            .then((res) => {
              console.log("projectActivitySave--", res);
              if (res.type == "success") {
                this.$message.success("更新项目活动成功");
                this.$router.push({
                  path: "/projectActivity/list",
                  query: {
                    companyId: this.companyId,
                    projectId: this.projectId,
                  },
                });
              }
            })
            .catch((err) => {
              this.$message.error(err.msg);
            });
        }
      });
    },

  },
};
</script>

<style lang="scss" scoped>
</style>
